home *** CD-ROM | disk | FTP | other *** search
/ Nejlepší hry / Nejlepsi hry.iso / hry / sea of chaos / sea_install.msi / _15C39AAA7726369D39812BD40F01CF6A / _1F6D7C1BA10141149AB5381619FC0885 < prev    next >
Text File  |  2005-01-15  |  2KB  |  91 lines

  1. //blurs objects along the direction they are moving
  2. //handles 2 directional lights and ambient
  3. //must be used with clipZ_lit.psh
  4. //Luke Lenhart
  5. //(C)2004-2005 Digipen Institute of Technology
  6.  
  7. //world,view,projection transform
  8. float4x4 matWorld;
  9. float4x4 matViewProj;
  10.  
  11. //2 directional lights
  12. float4 l1Direction;
  13. float4 l1Color;
  14.  
  15. float4 l2Direction;
  16. float4 l2Color;
  17.  
  18. //ambient light
  19. float4 lAmbient;
  20.  
  21. //direction of movement (normalized)
  22. float4 moveDir;
  23.  
  24. //speed of movement (should cap it to like 10)
  25. float speed;
  26.  
  27. //time step (in seconds) (clamp it from 0.05 to 0.25)
  28. float timeStep;
  29.  
  30. //shader input
  31. struct VS_INPUT
  32. {
  33.     float4 Pos : POSITION;
  34.     float4 Normal : NORMAL;
  35.     float2 Tex0 : TEXCOORD0;
  36. };
  37.  
  38. //shader output
  39. struct VS_OUTPUT
  40. {
  41.     float4 Pos : POSITION;
  42.     float2 Tex0 : TEXCOORD0;
  43.     float4 Color : COLOR;
  44. };
  45.  
  46. //shader code
  47. VS_OUTPUT VShader(VS_INPUT In)
  48. {
  49.     VS_OUTPUT Out;
  50.     
  51.     //trans to world
  52.     float4 pos=mul(matWorld,In.Pos);
  53.     float3 norm=mul(matWorld,In.Normal.xyz);
  54.     
  55.     //calc colors from directional lights
  56.     float4 l1Contrib=dot(-norm.xyz,l1Direction.xyz)*l1Color;
  57.     l1Contrib=saturate(l1Contrib);
  58.  
  59.     float4 l2Contrib=dot(-norm.xyz,l2Direction.xyz)*l2Color;
  60.     l2Contrib=saturate(l2Contrib);
  61.  
  62.     Out.Color=l1Contrib + l2Contrib + lAmbient;
  63.  
  64.     //stuff on the back side should blur, front side should go away
  65.     float blurMod=dot(norm.xyz,moveDir.xyz);
  66.     if (blurMod>0) //back side
  67.     {
  68.         //blur back stuff the most
  69.         Out.Color.a=1.0f - blurMod;
  70.         Out.Color.a*=Out.Color.a; //pow2 curve
  71.     
  72.         //push backside warp along direction of movement
  73.         pos.xyz+=-moveDir.xyz*blurMod*speed*timeStep;
  74.     }
  75.     else //front side
  76.     {
  77.         Out.Color.a=0;
  78.         
  79.         //pos.xyz-=norm.xyz*0.5f;
  80.     }
  81.     
  82.     //calc transformed position
  83.     Out.Pos=mul(matViewProj,pos);
  84.     
  85.     //copy tex coord
  86.     Out.Tex0=In.Tex0;
  87.  
  88.     //spit out the results
  89.     return Out;
  90. }
  91.